/**
 * 
 */
package com.ttt.radiostreammingservice;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

/**
 * @author sebastian.carrozzo
 * 
 */
class HeadsetBroadcastReceiver extends BroadcastReceiver {
	private boolean headsetConnected = false;
	private StreamingService service;

	private HeadsetBroadcastReceiver() {
		super();
	}

	HeadsetBroadcastReceiver(StreamingService service) {
		this();
		this.service = service;
	}

	@Override
	public void onReceive(Context context, Intent intent) {
		Log.v(RadioStreamingIntentService.TAG, "ACTION_HEADSET_PLUG Intent received");
		if (intent.hasExtra("state")) {
			if (headsetConnected && intent.getIntExtra("state", 0) == 0) {
				headsetConnected = false;
				service.setHeadsetSwitch(0);
				Log.v(RadioStreamingIntentService.TAG, "State =  Headset disconnected");
			} else if (!headsetConnected && intent.getIntExtra("state", 0) == 1) {
				headsetConnected = true;
				service.setHeadsetSwitch(1);
				Log.v(RadioStreamingIntentService.TAG, "State =  Headset connected");
			}
		}

		switch (service.getHeadsetSwitch()) {
		case (0):
			service.headsetDisconnected();
			break;
		case (1):
			break;
		}
	}
}